package my.Imitation.writing;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Tom
 * @Date: 2022/02/13/20:36
 * @Description:
 */

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 *@ClassName LRU
 *@Description
 *@Author 王琛
 *@Date 2022/2/13 20:36
 @Version 1.0
 */
public class LRUCache {
    Map<Integer, Integer> map;
    int maxSize;
    public LRUCache(int capacity) {
        map = new LinkedHashMap<Integer,Integer>(capacity,0.75f,true){
            @Override
            protected boolean removeEldestEntry(Map.Entry eld){
                return map.size() > capacity;
            }
        };
        maxSize = capacity;
    }

    public int get(int key) {
        return map.getOrDefault(key,-1);
    }

    public void put(int key, int value) {
        map.put(key, value);
    }

}
